package cn.zwx.activiti.example.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

/**
 * @description:
 * @projectName:activiti-example
 * @see:cn.zwx.activiti.example.security
 * @author:zhangwenxue
 * @createTime:2021/5/31 22:02
 * @version:1.0
 */
@Configuration
public class ActivitiSecurityConfig extends WebSecurityConfigurerAdapter {


    @Autowired
    private LoginSuccessHandler loginSuccessHandler;
    @Autowired
    private LoginFailureHandler loginFailureHandler;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .formLogin()
                // 登录接口
                .loginPage("/login")
                // 登录之前的判断
                .loginProcessingUrl("/login")
                .successHandler(loginSuccessHandler)
                .failureHandler(loginFailureHandler)
                //.defaultSuccessUrl("/hello")
                //.successForwardUrl("success.html")
                //.failureForwardUrl("failure.html")
                .and()
                .authorizeRequests()
                .antMatchers("/login", "/druid/**", "/demo-login1.html", "/layuimini/page/login-1.html").permitAll()
                .anyRequest()
                .permitAll().and().logout().permitAll().and()
                // 关闭 不然ajax 会变成
                .csrf()
                .disable().headers()
                // 关闭 不然 弹框报错
                .frameOptions().disable();//全部页面不验证
    }
}
